<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()" label-width="120px">
      <el-form-item label="主键" prop="id">
        <el-input v-model="dataForm.id" placeholder="主键"></el-input>
      </el-form-item>
      <el-form-item label="展位编号" prop="number">
        <el-input v-model="dataForm.number" placeholder="展位编号"></el-input>
      </el-form-item>
      <el-form-item label="展会id" prop="exhId">
        <el-input v-model="dataForm.exhId" placeholder="展会id"></el-input>
      </el-form-item>
      <el-form-item label="展馆id" prop="exhHallId">
        <el-input v-model="dataForm.exhHallId" placeholder="展馆id"></el-input>
      </el-form-item>
      <el-form-item label="展位面积" prop="area">
        <el-input v-model="dataForm.area" placeholder="展位面积"></el-input>
      </el-form-item>
      <el-form-item label="展位说明（4x4）" prop="description">
        <el-input v-model="dataForm.description" placeholder="展位说明（4x4）"></el-input>
      </el-form-item>
      <el-form-item label="展位类型 1空地 2标展" prop="type">
        <el-input v-model="dataForm.type" placeholder="展位类型 1空地 2标展"></el-input>
      </el-form-item>
      <el-form-item label="展位状态 1可售 2已付款 3未付款 4预留" prop="status">
        <el-input v-model="dataForm.status" placeholder="展位状态 1可售 2已付款 3未付款 4预留"></el-input>
      </el-form-item>
      <el-form-item label="市场价格" prop="marketPrice">
        <el-input v-model="dataForm.marketPrice" placeholder="市场价格"></el-input>
      </el-form-item>
      <el-form-item label="优惠价格" prop="price">
        <el-input v-model="dataForm.price" placeholder="优惠价格"></el-input>
      </el-form-item>
      <el-form-item label="购买人id" prop="buyId">
        <el-input v-model="dataForm.buyId" placeholder="购买人id"></el-input>
      </el-form-item>
      <el-form-item label="购买人公司名" prop="buyCompany">
        <el-input v-model="dataForm.buyCompany" placeholder="购买人公司名"></el-input>
      </el-form-item>
      <el-form-item label="购买时间" prop="buyTime">
        <el-input v-model="dataForm.buyTime" placeholder="购买时间"></el-input>
      </el-form-item>
      <el-form-item label="付款时间" prop="payTime">
        <el-input v-model="dataForm.payTime" placeholder="付款时间"></el-input>
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-button @click="visible = false">{{ $t("cancel") }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t("confirm") }}</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts">
import { defineComponent, reactive } from "vue";
import baseService from "@/service/baseService";
import { useDebounce } from "@/utils/utils";
export default defineComponent({
  setup() {
    return reactive({
      visible: false,
      dataForm: {
        id: "",
        number: "",
        exhId: "",
        exhHallId: "",
        area: "",
        description: "",
        type: "",
        status: "",
        marketPrice: "",
        price: "",
        buyId: "",
        buyCompany: "",
        buyTime: "",
        payTime: ""
      }
    });
  },
  computed: {
    dataRule() {
      return {};
    }
  },
  created() {
    this.dataFormSubmitHandle = useDebounce(this.dataFormSubmitHandle);
  },
  methods: {
    init() {
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataFormRef"].resetFields();
        if (this.dataForm.id) {
          this.getInfo();
        }
      });
    },
    // 获取信息
    getInfo() {
      baseService.get("/noc/texhstand/" + this.dataForm.id).then((res) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg);
        }
        this.dataForm = res.data;
      });
    },
    // 表单提交
    dataFormSubmitHandle() {
      this.$refs["dataFormRef"].validate((valid: boolean) => {
        if (!valid) {
          return false;
        }
        (!this.dataForm.id ? baseService.post : baseService.put)("/noc/texhstand", this.dataForm).then((res) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.$message({
            message: this.$t("prompt.success"),
            type: "success",
            duration: 500,
            onClose: () => {
              this.visible = false;
              this.$emit("refreshDataList");
            }
          });
        });
      });
    }
  }
});
</script>
